import axios from "../axios";

// sys User Api

// GET
// /user/{id}
// 根据 ID 查询用户
export const getUser = ({ id }) => {
  return axios.request({
    url: `/user/${id}`,
    method: "get",
  });
};

// PUT
// /user/assign
// 用户分配角色
export const userAssign = (params) => {
  const data = {
    roleIdList: params.roleIdList,
    userId: params.userId,
  };
  return axios.request({
    url: "/user/assign",
    data,
    method: "put",
  });
};

// GET
// /user/currentUser
// 获取当前用户信息
export const userCurrentUser = () => {
  return axios.request({
    url: "/user/currentUser",
    method: "get",
  });
};

// PUT
// /user/disabled/{id}
// 禁用用户
export const userDisabled = ({ id }) => {
  return axios.request({
    url: `/user/disabled/${id}`,
    method: "put",
  });
};

// PUT
// /user/enabled/{id}
// 启用用户
export const userEnabled = ({ id }) => {
  return axios.request({
    url: `/user/enabled/${id}`,
    method: "put",
  });
};

// PUT
// /user/findUserRoles/{id}
// 获取用户角色关系
export const userFindUserRoles = (params) => {
  const { id } = params;
  const data = {
    delFlag: params.delFlag,
    id: params.id,
  };
  return axios.request({
    url: `/user/findUserRoles/${id}`,
    data,
    method: "put",
  });
};

// POST
// /user/insert
// 新增用户
export const userInserts = (params) => {
  const data = {
    accountExpiredDt: params.accountExpiredDt,
    accountLocked: params.accountLocked,
    age: params.age,
    credentialsExpiredDt: params.credentialsExpiredDt,
    delFlag: params.delFlag,
    email: params.email,
    enabled: params.enabled,
    id: params.id,
    nickName: params.nickName,
    password: params.password,
    phone: params.phone,
    username: params.username,
  };
  return axios.request({
    url: `/user/insert/`,
    data,
    method: "put",
  });
};

// PUT
// /user/locked/{id}
// 锁定用户
export const userLocked = ({ id }) => {
  return axios.request({
    url: `/user/locked/${id}`,
    method: "put",
  });
};
// GET
// /user/page
// 分页查询
export const userPage = (params) => {
  const data = {
    accountLocked: params.accountLocked || 0, // 锁定 (异常操作) 0:否 1:是
    age: params.age, // 性别
    delFlag: params.delFlag || 0, // 是否删除状态 0:否 1:是
    email: params.email, // 邮箱
    enabled: params.enabled || 0, //禁用 (离职等原因) 0:否 1:是
    nickName: params.nickName, // 昵称
    pageNumber: params.pageNumber, // 页码
    pageSize: params.pageSize, // 页大小
    phon: params.ephone, // 手机
    roleName: params.roleName, // 角色
    username: params.username, // 用户
  };
  return axios.request({
    url: `/user/page/`,
    params: data,
    method: "get",
  });
};
// PUT
// /user/recovery/{id}
// 恢复用户
export const userRecovery = ({ id }) => {
  return axios.request({
    url: `/user/recovery/${id}`,
    method: "put",
  });
};
// PUT
// /user/unlocked/{id}
// 解锁用户

// PUT
// /user/update
// 更新用户

// pageDeamd 分页查询
export const getDeamd = (params) => {
  const data = {
    delFlag: params.delFlag,
    demandCode: params.demandCode,
    pageNumber: params.pageNumber,
    pageSize: params.pageSize,
    projectId: params.projectId,
    skill: params.skill,
    skillLevel: params.skillLevel,
    workPlace: params.workPlace,
  };
  return axios.request({
    url: "/demand/page",
    params: data,
    method: "get",
  });
};

// recoveryDemand 恢复招聘需求
export const recoveryDemand = (params) => {
  const { id } = params;
  return axios.request({
    url: `/demand/recovery/${id}`,
    method: "put",
  });
};

// update demand 更新招聘需求
export const updateDemand = (params) => {
  const data = {
    demandCode: params.demandCode, // 需求编码
    id: params.id, // 主键
    introduction: params.introduction, // 需求简介
    peopleNumber: params.peopleNumber, // 需求人数
    projectId: params.projectId, // 项目ID
    skill: params.skill, // 技能（string）
    skillLevel: params.skillLevel, // 技能级别 （string）
    workPlace: params.workPlace, // 需求地点
  };
  return axios.request({
    url: "/demand/update",
    data,
    method: "put",
  });
};
